﻿@{
    ViewBag.Title = "RunningLog";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
    ViewBag.PageTitle = "统计数据";
    ViewBag.PageColumn = "运行日志";
}
<div class="count-panel" style="width:100%;margin:0px auto;">
    <div class="x_title">
        <div class="clearfix">
            <div class="panel-body" style="padding:0px;">
                <form id="formSearch" class="form-horizontal">
                    <div class="panel panel-default">
                        <div class="panel-heading " id="pal-text"><span class="glyphicon glyphicon-filter" aria-hidden="true"></span>&nbsp;查询条件<span style="float:right;"><a href="javascript:;" style="text-decoration:none" class="Inquire-text" id="btn_query"><span class="glyphicon glyphicon-search" aria-hidden="true"></span>&nbsp;查询</a></span></div>
                        <div class="panel-body">

                            <div class="form-group">
                                <label class="control-label col-sm-1" for="txt_search_rolename">日志时间</label>
                                <div class="col-sm-3">
                                    <div class="input-group date log_datetime col-sm-12" data-link-field="dt_set_order_time_input">
                                        <input id="query_log_time" class="form-control" disabled type="text" value="@DateTime.Now.ToString("yyyy-MM-dd")">
                                        <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                                        <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                                    </div>
                                </div>

                                <label class="control-label col-sm-1" for="txt_search_desc">开始时间</label>
                                <div class="col-sm-3">
                                    <div class="input-group date form_datetime col-sm-12" data-link-field="dt_set_order_time_input">
                                        <input id="query_start_time" class="form-control" disabled type="text">
                                        <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                                        <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                                    </div>
                                </div>
                                <label class="control-label col-sm-1" for="txt_search_desc">结束时间</label>
                                <div class="col-sm-3">
                                    <div class="input-group date form_datetime col-sm-12" data-link-field="dt_set_order_time_input">
                                        <input id="query_end_time" class="form-control" disabled type="text">
                                        <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                                        <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                                    </div>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="control-label col-sm-1" for="txt_search_rolename">AGV编号</label>
                                <div class="col-sm-3">
                                    <input id="query_agv_num" type="text" class="form-control">
                                </div>
                                <label class="control-label col-sm-1" for="txt_search_desc">任务状态</label>
                                <div class="col-sm-3">
                                    <select id="query_task_status" class="selectpicker show-tick form-control">
                                        <option value="0">全部</option>
                                        <option value="1">已完成</option>
                                        <option value="2">进行中</option>
                                        <option value="3">未完成</option>
                                    </select>
                                </div>
                                <label class="control-label col-sm-1" for="txt_search_desc">AGV状态</label>
                                <div class="col-sm-3">
                                    <select id="query_agv_status" class="selectpicker show-tick form-control" data-live-search="false">
                                        <option>全部</option>
                                        <option>正常</option>
                                        <option>报警</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>

                <div class="panel panel-default">
                    <div class="panel-heading" id="pal-text"><span class="glyphicon glyphicon-cog" aria-hidden="true"></span>&nbsp;数据列表<a href="javascript:;" id="export" style="float:right;text-decoration:none"><sapn class="Inquire-text"><span class="glyphicon glyphicon-open" aria-hidden="true"></span>&nbsp;导出</sapn></a></div>
                    <div class="panel-body" style="padding:10px;">
                        <table id="tb_report"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {

        //1.初始化Table
        var oTable = new TableInit();
        oTable.Init();

        $('.log_datetime').datetimepicker({
            minView: "month", //选择日期后，不会再跳转去选择时分秒
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            todayBtn: 1,
            autoclose: 1,
        });

        $('.form_datetime').datetimepicker({
            minView: "hour",
            autoclose: true,
            weekStart: 1,                       //Integer. 默认值：0 一周从哪一天开始。0（星期日）到6（星期六）
            todayHighlight: true,
            startView: 1,                       //日期时间选择器打开之后首先显示的视图。0-4
            forceParse: 0,
            language: 'zh-CN',
            format: 'hh:ii:ss',
            pickerPosition: 'bottom-left',
            showMeridian: 1
        });

        $("#btn_query").click(function () {
            $("#tb_report").bootstrapTable('destroy'); //先要将table销毁，否则会保留上次加载的内容
            oTable.Init();
            $("#tb_report").bootstrapTable('refresh');
        });
    });

    //导出日志
    $('#export').click(function () {
        toastr.info('系统处理中请稍等！');
        $.ajax({
            type: 'post',
            url: '/api/File/Filelog',
            contentType: 'application/json',
            data: JSON.stringify({ "agvLogTime": $("#query_log_time").val() }),
            datatype: 'json',
            success: function (res) {
                if (res.Success) {
                    toastr.success(res.Message);
                    window.location.href = '/Log/' + res.Data + '';
                }
                else {
                    toastr.error(res.Message);
                }
            },
            error: function (e) {
                toastr.error(e.responseText);
            }
        });
    });

    var TableInit = function () {
        var oTableInit = new Object();
        //初始化Table
        oTableInit.Init = function () {
            $('#tb_report').bootstrapTable({
                url: '/api/agvlog/Log',             //请求后台的URL（*）
                method: 'get',                      //请求方式（*）
                toolbar: '#toolbar',                //工具按钮用哪个容器
                striped: true,                      //是否显示行间隔色
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,                   //是否显示分页（*）
                sortable: false,                    //是否启用排序
                sortOrder: "asc",                   //排序方式
                queryParams: oTableInit.queryParams,//传递参数（*）
                sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,                      //初始化加载第一页，默认第一页
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 25, 50, 100, 500],   //可供选择的每页的行数（*）
                search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端
                strictSearch: true,
                showColumns: true,                  //是否显示所有的列
                showRefresh: true,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                //height: 500,                      //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "ID",                     //每一行的唯一标识，一般为主键列
                showToggle: true,                   //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: false,

                columns: [{
                    field: 'agvNum',
                    title: 'AGV编号',
                    align: 'center'
                }, {
                    field: 'agvLogTime',
                    title: '时间',
                    align: 'center'
                }, {
                    field: 'agvSerialNo',
                    title: 'AGV序列号',
                    align: 'center'
                }, {
                    field: 'agvIp',
                    title: 'IP',
                    align: 'center'
                }
                    , {
                    field: 'agvPort',
                    title: '端口',
                    align: 'center'
                },
                {
                    field: 'agvQRInfo',
                    title: '二维码',
                    align: 'center'
                },
                {
                    field: 'agvX',
                    title: 'X轴',
                    align: 'center'
                },
                {
                    field: 'agvY',
                    title: 'Y轴',
                    align: 'center'
                },
                {
                    field: 'agvPowerStatus',
                    title: '电压',
                    align: 'center'
                },
                {
                    field: 'agvSpeed',
                    title: '速度',
                    align: 'center'
                },
                {
                    field: 'agvHolder',
                    title: '云台状态',
                    align: 'center'
                },
                {
                    field: 'agvAng',
                    title: '角度',
                    align: 'center'
                },
                {
                    field: 'agvScanner',
                    title: '扫描区域',
                    align: 'center'
                },
                {
                    field: 'agvIsRunning',
                    title: '是否运行',
                    align: 'center'
                },
                {
                    field: 'agvStaus',
                    title: '状态信息',
                    align: 'center'
                },
                {
                    field: 'agvIsCharging',
                    title: '充电',
                    align: 'center'
                },
                {
                    field: 'agvTask',
                    title: '任务',
                    align: 'center'
                },
                {
                    field: 'agvTaskStatus',
                    title: '任务状态',
                    align: 'center', formatter: function (value, row, index) {
                        if (value == null) {
                            return "全部";
                        } if (value == '1') {
                            return "<span class='label label-success'>已完成</span>";
                        } if (value == '2') {
                            return "<span class='label label-errer'>已取消</span>";
                        } if (value == '3') {
                            return "<span class='label label-move'>进行中</span>";
                        }
                    }
                },
                {
                    field: 'agvErrorCode',
                    title: '错误代码',
                    align: 'center'
                }
                ]
            });
        };

        //得到查询的参数
        oTableInit.queryParams = function (params) {
            var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                limit: params.limit,   //页面大小
                offset: params.offset,  //页码
                query_log_time: $("#query_log_time").val(),
                query_start_time: $("#query_start_time").val(),
                query_end_time: $("#query_end_time").val(),
                query_agv_num: $("#query_agv_num").val(),
                query_task_status: $("#query_task_status").val(),
                query_agv_status: $("#query_agv_status").val(),
            };
            return temp;
        };
        return oTableInit;
    };
</script>